﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class NPC : MonoBehaviour
{
    [SerializeField]
    private MovingObject movingScript;
    [SerializeField]
    private float minActivationInterval, maxActivationInterval, movePauseTime;
    [SerializeField]
    private NPCStatuses activedStatus, deactivetedStatus;
    [SerializeField]
    private SpriteRenderer statusHolder; 
    private float timer, currentInterval;
    private bool isActivated;
    private void Awake()
    {
        currentInterval = UnityEngine.Random.Range(minActivationInterval, maxActivationInterval);
    }
    // Start is called before the first frame update
    void Start()
    {
        movingScript.Initialize(movePauseTime, statusHolder, activedStatus, deactivetedStatus);
    }

    // Update is called once per frame
    void Update()
    {
        //if in the move, don't count time
        if (isActivated)
            return;

        timer += Time.deltaTime;
        if(timer > currentInterval)
        {
            timer = 0;
            currentInterval = UnityEngine.Random.Range(minActivationInterval, maxActivationInterval);
            movingScript.OnActivate();
        }
    }
}
